<template>
  <div class="app-container">
    <el-button type="primary" round style="margin-bottom: 10px" @click="dialogVisible = true">添加测试号</el-button>
    <el-table
      :data="list"
      border
      style="width: 100%">
      <el-table-column
        prop="date"
        label="账号"
        width="180">
        <template slot-scope="scope">
          {{ scope.row.phone }}
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="添加账号">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleAddTestAccount">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import {addTestAccount, getTestAccount} from "@/api/user";

export default {
  data() {
    return {
      form: {
        phone: ''
      },
      dialogVisible: false,
      list: []
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    handleAddTestAccount() {
      this.dialogVisible = false
      addTestAccount({phone: this.form.phone}).then(res => {
        this.form.phone = ''
        this.fetchData()
        this.$message({
          type: 'success',
          message: '添加成功!'
        })
      })
    },
    fetchData() {
      getTestAccount().then(res => {
        this.list = res.data.map(phone => {
          return { 'phone': phone }
        })
      })
    }
  }
}
</script>
